from flask import Flask


class ApiConfig:
    __API_PREFIXES__ = "API_PREFIXES"
    __API_VERSION__ = "API_VERSION"

    def __init__(self, app: Flask):
        self.app = app

    def config_param(self):
        api_prefix = self.app.config.get(self.__API_PREFIXES__)
        api_version = self.app.config.get(self.__API_VERSION__)

        return {
            "api_prefix": api_prefix,
            "api_version": api_version
        }

    @property
    def api_url_prefix(self):
        prefix = self.get_config("api_prefix")
        version = self.get_config("api_version")
        return f"/{prefix}/{version}"

    def get_config(self, key):
        config = self.config_param()
        return config.get(key)


def register_blueprint(app: Flask):
    api_config = ApiConfig(app=app)
    api_url_prefix = api_config.api_url_prefix
    print(api_url_prefix)
    from epp.api.user import user_rt

    app.register_blueprint(user_rt, url_prefix=f'{api_url_prefix}/user')
